﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using E_Shop.Common;
using ESHOP.Domain;
using ESHOP.DAO;
using ESHOP.UTIL;

namespace E_Shop
{
    public partial class ShoppingCheckOut : Authentication 
    {
        private SanPhamDAO _sanphamDao = new SanPhamDAO();
        private SANPHAM _sanpham = new SANPHAM();
        private GIOHANG _giohang = new GIOHANG();
        protected void Page_Load(object sender, EventArgs e)
        {
            GIOHANG giohang = (GIOHANG)Session[Constants.SESSION_GIOHANG];
            _giohang = giohang;
            _sanpham = _sanphamDao.Get(giohang.MASP);
            if (!IsPostBack)
            {
                
                lcsoluong.Text = giohang.SOLUONG.ToString();                
                lbSubtotal.Text = "US $" + giohang.GIA;
                lbShip.Text = "US $10";
                lbGrantotal.Text = (giohang.GIA + 10).ToString();
                lbtotal.Text = "US $" + giohang.GIA;
                lbDecrip.Text = giohang.SANPHAM.CHITIET;
                lbPrice.Text = "US $" + giohang.SANPHAM.GIA.ToString();
                ImageProduct.ImageUrl = "../Images/Product/" + _sanpham.HINHANH;
            }
            ResetCost();
        }

        public void ResetCost()
        {
            decimal soluong = decimal.Parse(lcsoluong.Text);
            decimal price = decimal.Parse( _sanpham.GIA.ToString());
            decimal total = soluong*price;
            lbSubtotal.Text = total.ToString();

            lbSubtotal.Text = total.ToString();
            lbGrantotal.Text = (total + 10).ToString();
            lbtotal.Text = total.ToString();

        }
        protected void lcsoluong_TextChanged(object sender, EventArgs e)
        {
            ResetCost();  
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string str ="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=conghai02@gmail.com";
            str+="&item_name="+_giohang.SANPHAM.TENSANPHAM;
            str+="&currency_code=USD";
            str += "&amount="+_giohang.SANPHAM.GIA.ToString().Substring(0,4);
            str += "&quantity="+lcsoluong.Text.Trim();
            str += "&shipping=10";
            Response.Redirect(str, true);


        }
        
    }
}